#include <stdio.h>
#include <stdlib.h>

void my_exit1(int i, void *arg)
{
    printf("exit1 %d %s\n", i, (char *)arg);
}

void my_exit2(int i, void *arg)
{
    printf("exit2 %d %s\n", i, (char *)arg);
}

int main(int argc, char const* argv[])
{
    if (on_exit(my_exit2, (void *)"first") != 0)
    {
        perror("on_exit error");
        exit(0);
    }
    if (on_exit(my_exit1, (void *)"second") != 0)
    {
        perror("on_exit error");
        exit(0);
    }
    if (on_exit(my_exit1, (void *)"third") != 0)
    {
        perror("on_exit error");
        exit(0);
    }
    printf("main is done\n");
    return 0;
}

